package org.example.xiaomi.controller;


import org.example.xiaomi.dao.impl.CategoryServiceImpl;
import org.example.xiaomi.entity.Category;
import org.example.xiaomi.service.CategoryService;
import org.example.xiaomi.util.HttpResponseUtil;
import org.example.xiaomi.util.MyBeanUtils;
import org.example.xiaomi.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/category/edit")
public class CategoryEditController extends HttpServlet {
    private CategoryService categoryService = new CategoryServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取参数
        Category category = new Category();
        MyBeanUtils.populate(category, req.getParameterMap());
        System.out.println(category);
        //2 调用业务层
        ResultVO resultVO=categoryService.updateCategory(category);
        //3 json
        HttpResponseUtil.response(resp, resultVO);
    }
}
